#ifndef TCPSERVER_H
#define TCPSERVER_H

#include <QDialog>
#include <QTcpServer>
#include <QTcpSocket>
#include <QFile>
#include <QElapsedTimer>

namespace Ui {
class TcpServer;
}

class TcpServer : public QDialog
{
    Q_OBJECT

public:
    explicit TcpServer(QWidget *parent = nullptr);
    ~TcpServer();
    void initServer();
    void refused();

protected:
    void closeEvent(QCloseEvent *);

private:
    Ui::TcpServer *ui;
    qint16 tcpPort; // 端口
    QTcpServer *tcpServer; // tcp服务
    QTcpSocket *clientConnection; // 新连接socket
    qint64 TotalBytes; // 总数据大小
    qint64 bytesWritten; // 已发送数据的大小
    qint64 bytesToWrite;
    qint64 payloadSize;
    QString theFileName; // 发送的文件名
    QString fileName;    // 文件名
    QFile *localFile; // 文件描述
    QByteArray outBlock; // 发送数据块
    QElapsedTimer elapsedTime;
signals:
    void sendFileName(QString fileName);
private slots:
    void sendMessage();
    void updateClientProgress(qint64 numBytes);

    void on_serverOpenBtn_clicked();
    void on_serverSendBtn_clicked();
    void on_serverColseBtn_clicked();
};

#endif // TCPSERVER_H
